#include<vector>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using std::max;
using std::vector;
using std::unordered_map;
using std::unordered_set;


class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        unordered_set<int> mp;
        for (auto n: nums) mp.insert(n);
        int ans = 0;
        for (auto n: nums) {
            if (mp.find(n-1) != mp.end()) continue;
            int curLen = 1;
            while (mp.find(n+1) != mp.end()) {
                curLen++;
                n++;
            }
            ans = max(ans, curLen);
        }
        return ans;
    }
};